/*******************************************
 *                                         *
 *******************************************/

#include "Text.h"

namespace DirectXFramework
{
	namespace Graphics
	{
		Text::Text (void)
		{
			this->TextFont = NULL;
			this->TextSprite = NULL;
			this->TextString = "Text";
			SetRect(&this->TextBox, 0, 0, MAX_TEXT_WIDTH, MAX_TEXT_HEIGHT);
			this->Format = DT_LEFT;
			this->Color = COLOR(255, 255, 255);
		}

		Text::Text (LPDIRECT3DDEVICE9 DrawDevice, UINT TextSize, BOOL Italic, LPCWSTR Font)
		{
			this->TextFont = NULL;
			this->TextSprite = NULL;
			this->TextString = "Text";
			SetRect(&this->TextBox, 0, 0, MAX_TEXT_WIDTH, MAX_TEXT_HEIGHT);
			this->Format = DT_LEFT | DT_TOP;
			this->Color = COLOR(255, 255, 255);
			this->Init(DrawDevice, TextSize, Italic, Font);
		}

		Text::~Text (void)
		{
		}

		BOOL Text::Init (LPDIRECT3DDEVICE9 DrawDevice, UINT TextSize, BOOL Italic, LPCWSTR Font)
		{
			BOOL Success = TRUE;

			this->Size = TextSize;

			if (FAILED(D3DXCreateFont(DrawDevice, this->Size, 0, FW_NORMAL, 1, Italic, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS,
									  DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, Font, &this->TextFont)))
				Success = FALSE;

			return Success;
		}

		void Text::Draw (void)
		{
			this->TextFont->DrawTextA(this->TextSprite, this->TextString, (int)strlen(this->TextString),
									  &this->TextBox, this->Format, this->Color);
		}

		void Text::SetFormat (DWORD FormatFlags)
		{
			this->Format = FormatFlags;
		}

		void Text::SetText (LPCSTR DisplayText)
		{
			this->TextString = DisplayText;
		}

		void Text::SetColor (DWORD TextColor)
		{
			this->Color = TextColor;
		}

		void Text::SetLocation (LONG X, LONG Y)
		{
			SetRect(&this->TextBox, X, Y, X + MAX_TEXT_WIDTH, Y + MAX_TEXT_HEIGHT);
		}
	};
};